Passed
Push — master ( e1efef...d34f83 )
by
unknown
15:24
created

HeadingMenuItemDispatcher.getMenuItem   A

Complexity

Conditions 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
c 0
b 0
f 0
dl 0
loc 10
rs 10
1
import { setBlockType } from 'prosemirror-commands';
2
import AbstractMenuItemDispatcher from './AbstractMenuItemDispatcher';
3
import MenuItem from '../MenuItem';
4
import { svgIcon } from '../MDI';
5
6
export default class HeadingMenuItemDispatcher extends AbstractMenuItemDispatcher {
7
    /**
8
     * Create an MenuItemDispatcher to set the blocktype to a heading at the given level
9
     *
10
     * @param {int} level the level of the heading, from 1 to 6
11
     */
12
    constructor(level) {
13
        super();
14
        this.level = level;
15
    }
16
17
    isAvailable(schema) { // eslint-disable-line class-methods-use-this
18
        return !!schema.nodes.heading;
19
    }
20
21
    getMenuItem(schema) {
22
        if (!this.isAvailable(schema)) {
23
            throw new Error('Headings not available in this schema!');
24
        }
25
        return new MenuItem({
26
            command: setBlockType(schema.nodes.heading, { level: this.level }),
27
            icon: svgIcon(`format-header-${this.level}`),
28
            label: LANG.plugins.prosemirror['label:heading'].replace(/%s/, this.level),
0 ignored issues
show
Bug introduced by
The variable LANG seems to be never declared. If this is a global, consider adding a /** global: LANG */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
29
        });
30
    }
31
}
32